package net.lovesrc.allin.jobs.backup;

import net.lovesrc.allin.biz.stl.StlService;
import net.lovesrc.allin.jobs.base.BaseJob;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;

//@Component
@Profile("live")
public class StlProfitJob extends BaseJob {

    @Autowired
    private StlService stlService;

    @Override
    public void runOnce() throws Exception {
        if (RandomUtils.nextInt(0, 100) == 10 && stlService.isNotJyTime()) {
            jdbcTemplate.update("update t_stl_account set nextProfitTime = date(now()) + interval (5 + rand() * 4) * 60 * 60 second" +
                    " where nextProfitTime < date(now()) and worked = 1");
        }
        stlService.profits(5);
    }

    @Override
    protected long intervalMilliseconds() {
        return 1000 * RandomUtils.nextInt(5, 10);
    }

}
